Help with Flask-ask and GPIO

by: NotJoe, 8 years ago


Right hopefully this is an easy one and I'm just being a tit. brand new to python so please be gentle.

I've followed the tutorial on getting amazon echo to talk to my raspberry and it works beautifully. The part I have added is the GPIO parts in the yes intent so that it flashed a LED when it receives a yes answer from the echo and again it works perfectly. but my question is how can I make it so there is a delay on the GPIO so that the alexa response speaks then the LED flashes? I've tried creating a variable in the yes intent that gets set to '1' when she answers. then tried to return it at the end by adding ", variableName" then creating a if command outside of the yes intent function but the variable never seemed to come out of the yesintent. I also tried defining the variable as global but still no joy. I just can't think of anything else to google to do this and I wondered if anyone could help?

the code is as follows:


from flask import Flask
from flask_ask import Ask, statement, question, session
import json
import requests
import time
import unidecode
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)

app = Flask(__name__)
ask = Ask(app, "/shocker")

@app.route('/')
def homepage():
    welcome = 'hi there, how the fluff is it?'
    return statement(welcome)

@ask.launch
def start_skill():
    welcome_message = 'Hello there, would you like me to do something?'
    return question(welcome_message)

@ask.intent("YesIntent")
def yes_intent():
    GPIO.setwarnings(False)
    GPIO.setup(7, GPIO.OUT)
    GPIO.output(7,1)
    time.sleep(1)
    GPIO.output(7,0)
    yes_message = 'the thing has been done'
    return statement(yes_message)

@ask.intent("NoIntent")
def no_intent():
    no_message = 'well then why are you wasting my time?'
    return statement(no_message)

if __name__ == '__main__':
    app.run()




You must be logged in to post. Please login or register an account.